package indi.kider.server.applandlord.api;

import indi.kider.common.model.bill.MeterControl;
import indi.kider.common.model.bill.MeterReadingQuery;
import indi.kider.common.model.bill.MeterRecord;
import indi.kider.common.model.bill.RentMeter;
import indi.kider.common.model.meter.CommandResponse;
import indi.kider.server.applandlord.service.related.BalanceBill;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pers.vankid.common.model.base.CommonResponse;
import pers.vankid.common.utils.page.PageRequest;
import pers.vankid.common.utils.page.PageResponse;

import java.util.List;

/**
 * Created by shixj on 2018/5/28.
 */
@RestController
@RequestMapping(value = "meter", produces = "application/json;charset=UTF-8")
public class MeterController {
    @Autowired
    private BalanceBill balanceBill;

    /**
     * @api {PUT} meter/command
     * @apiGroup app-landlord
     * @apiDescription 拉合闸  meterType:1水2电  opType;//0合闸1拉闸
     * @apiParamExample 请求样例：
     * http://localhost:9002/app-landlord/meter/command
     * {"housesId":1,"meterType":1,"opType":1}
     * @apiSuccessExample {json} 返回样例:
     * {"status":"200","msg":"操作成功！","data":null}}
     * {"status":"400","msg":"命令执行失败！","data":null}}
     */
    @PutMapping("command")
    public CommonResponse<CommandResponse> meterControl(@RequestBody MeterControl meterControl) {
        return balanceBill.meterControl(meterControl);
    }

    /**
     * @api {POST} meter/reading
     * @apiGroup app-landlord
     * @apiDescription 智能抄表 meterType:1水2电  rentId:未出租房屋传0或null
     * @apiParamExample 请求样例：
     * http://localhost:9002/app-landlord/meter/reading
     * {"rentId":1,"housesId":70,"meterType":1}
     * @apiSuccessExample {json} 返回样例:
     * {"status":"200","msg":"查询成功！","data":1.01}
     */
    @PostMapping("mannal")
    public CommonResponse mannalRead(@RequestBody MeterReadingQuery meterReadingQuery) {
        return balanceBill.mannalRead(meterReadingQuery);
    }

    /**
     * @api {POST} meter/list
     * @apiGroup app-landlord
     * @apiDescription 查询表具列表 expression支持houseNumb，address，tenantTel，tenantName模糊匹配
     * @apiParamExample 请求样例：
     * http://localhost:9002/app-landlord/meter/list
     * {"size":999,"num":1,"query":{"expression":1,"meterType":1}}
     * @apiSuccessExample {json} 返回样例:
     * {"status":"200","msg":"查询成功！","data":{"rows":[{"id":1,"housesId":69,"meterCode":"110","meterType":1,"locationParam":1,"concentrator":"1","name":"谁的表","rentId":87,"tenantName":"1","tenantTel":"1","houseNumb":"WN_0000","building":null,"unit":null,"address":"蒋村","community":"都市水乡","communityId":null,"expression":null,"enterpriseId":null}],"total":1,"size":1}}
     */
    @PostMapping("list")
    public CommonResponse<PageResponse<List<RentMeter>>> getRentMeterList(@RequestBody PageRequest<RentMeter> request) {
        return balanceBill.getRentMeterList(request);
    }

    /**
     * @api {POST} meter/record/list
     * @apiGroup app-landlord
     * @apiDescription 查询读数列表  meterType：1水2电
     * @apiParamExample 请求样例：
     * http://localhost:9002/app-landlord/meter/record/list
     * {"size":999,"num":1,"query":{"rentId":1,"meterType":1}}
     * @apiSuccessExample {json} 返回样例:
     * {"status":"200","msg":"查询成功！","data":{"rows":[{"title":"2018年05月份","thisRead":3.0,"thisReadTime":"2018-05-28 09:54","lastRead":0.0,"lastReadTime":null,"absoluteNumber":3.0},{"title":"2018年05月份","thisRead":3.0,"thisReadTime":"2018-05-28 09:54","lastRead":1.0,"lastReadTime":null,"absoluteNumber":2.0}],"total":2,"size":1}}
     */
    @PostMapping("record/list")
    public CommonResponse<PageResponse<List<MeterRecord>>> getMeterRecordList(@RequestBody PageRequest<RentMeter> request) {
        return balanceBill.getMeterRecordList(request);
    }
}
